package thread.exercise.ex9_2;

class InSync extends Thread {
	  StringBuffer letter;     
	  public InSync(StringBuffer letter) { this.letter = letter; } 
	  public void run() {
//	    synchronized(letter) {      // #1
	      for(int i = 1;i<=1000;++i) 
	    	  {
	    	  System.out.print(Thread.currentThread().getId());
	    	  	System.out.print(letter);
	    	  }
	      System.out.println();
	      char temp = letter.charAt(0);
	      ++temp;         // Increment the letter in StringBuffer:
	      letter.setCharAt(0, temp);
	    }     // #2
//	  }
	  public static void main(String [] args) {
	    StringBuffer sb = new StringBuffer("A");
	    new InSync(sb).start();  
	    new InSync(sb).start();
	    new InSync(sb).start();
	  } 
	}
